import scrapy
from ..items import RewardItem



class CaipiaoSpider(scrapy.Spider):
    name = "caipiao"
    allowed_domains = ["datachart.500.com"]
    start_urls = ["https://datachart.500.com/ssq/"]

    def parse(self, response, **kwargs):
        list = []
        tdata = response.xpath("//tbody[@id='tdata']/tr")
        for record in tdata:
            if record.xpath('./@class').extract_first() == 'tdbck':
                print(111)
                continue
            # scrapy的xpath即使标签的类中含有多个，写其中的一个也可以找出来
            qi_hao = record.xpath("./td[@align='center']/text()").extract_first()
            red_list = record.xpath("./td[@class='chartBall01']/text()").extract()
            blue_list = record.xpath("./td[@class='chartBall02']/text()").extract()
            item = RewardItem(qi_hao=qi_hao, red_list=red_list, blue_list=blue_list)
            yield item
